@extends('base')

@section('content')
<div class="layui-row layui-col-space10">
    <div class="layui-col-md8 layui-col-lg-offset2">
        <div class="layui-card">
            <div class="layui-card-header">系统基本设置</div>
            <div class="layui-card-body layui-row layui-col-space10">
                <form class="layui-form" name="edit_form" lay-filter="edit_form">
                    <div class="layui-col-md12">
                        <div class="layui-form-item">
                            <label class="layui-form-label">名称：</label>
                            <div class="layui-input-block">
                                <input type="text" name="system_name" value="{{ $data['system_name'] }}" lay-verify="required" placeholder="请输入名称" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">域名：</label>
                            <div class="layui-input-block">
                                <input type="text" name="system_url" value="{{ $data['system_url'] }}" lay-verify="required" placeholder="请输入域名" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">LOGO：</label>
                            <div class="layui-input-inline" style="width: 500px;">
                                <input type="text" name="system_logo" id="system_logo" value="{{ $data['system_logo'] }}" placeholder="请上传LOGO" class="layui-input" style="width: 500px">
                            </div>
                            <div class="layui-input-inline">
                                <button type="button" class="layui-btn pear-btn-primary" id="upload-btn"> <i class="layui-icon">&#xe67c;</i> 上传图片 </button>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">标题：</label>
                            <div class="layui-input-block">
                                <input type="text" name="seo_title" value="{{ $data['seo_title'] }}" lay-verify="required" placeholder="请输入标题" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">关键词：</label>
                            <div class="layui-input-block">
                                <input type="text" name="seo_keyword" value="{{ $data['seo_keyword'] }}" lay-verify="required" placeholder="请输入关键词" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">描述：</label>
                            <div class="layui-input-block">
                                <input type="text" name="seo_description" value="{{ $data['seo_description'] }}" lay-verify="required" placeholder="请输入描述" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">版权信息：</label>
                            <div class="layui-input-block">
                                <input type="text" name="system_copy" value="{{ $data['system_copy'] }}" lay-verify="required" placeholder="请输入版权信息" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">备案号：</label>
                            <div class="layui-input-block">
                                <input type="text" name="system_icp" value="{{ $data['system_icp'] }}" lay-verify="required" placeholder="请输入备案号" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">微信号：</label>
                            <div class="layui-input-block">
                                <input type="text" name="contact_wechat" value="{{ $data['contact_wechat'] }}" lay-verify="required" placeholder="请输入微信号" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">手机号：</label>
                            <div class="layui-input-block">
                                <input type="text" name="contact_phone" value="{{ $data['contact_phone'] }}" lay-verify="required" placeholder="请输入手机号" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label"></label>
                            <div class="layui-input-block">
                                <button type="submit" class="pear-btn pear-btn-primary" lay-submit lay-filter="edit-save"><i class="layui-icon layui-icon-ok"></i>提交</button>
                                <button type="reset" class="pear-btn"><i class="layui-icon layui-icon-refresh"></i>重置</button>
                            </div>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
@endsection

@section('js')
<script>
    layui.use(['form', 'jquery', 'upload'], function() {
        let form = layui.form;
        let $ = layui.jquery;
        let upload = layui.upload;

        upload.render({
            elem: '#upload-btn' //绑定元素
            ,url: '/upload/upload' //上传接口
            ,accept: 'image'
            ,acceptMime: 'image/*'
            ,field: 'upload_name'
            ,size: 2048
            ,data: {upload_type: 'image'}
            ,headers: {
                'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
             }
            ,done: function(res){
                if (res.error === 0){
                    $('#system_logo').val(res.url)
                }else {
                    layer.msg(res.message, {icon: 2, time: 1000})
                }
            }
            ,error: function(){
                layer.msg('网络异常！', {icon: 2, time: 1000})
            }
        });

        form.on('submit(edit-save)', function(data) {
            $.ajax({
                url: '{{ route('config.edit') }}',
                data: JSON.stringify(data.field),
                dataType: 'json',
                contentType: 'application/json',
                type: 'post',
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                },
                success: function(result) {
                    if (result.status) {
                        layer.msg(result.msg, {icon: 1, time: 1000}, function() {
                            parent.layui.admin.refreshThis()
                        });
                    } else {
                        layer.msg(result.msg, {icon: 2, time: 1000});
                    }
                }
            })
            return false;
        });
    })
</script>
@endsection


